// All contents of this file written by Colin Fahey ( http://colinfahey.com )
// 2007 June 4 ; Visit web site to check for any updates to this file.



using System;
using System.Collections.Generic;
using System.Text;

using CPF.GRV10;



namespace CPF.StandardTetris
{
    public class STOpenGLFont
    {

        public const int FONT_WIDTH = 8;
        public const int FONT_HEIGHT = 16;

        // The following 128 x 128, 1-bit-per-pixel bitmap is
        // Courier New 10pt font, where each character is in a
        // 8x16 pixel cell.  The character grid on the image 
        // is 16 x 8 characters.
        // The first 96 chars are ASCII chars 32..127.
        // The last  32 chars are ASCII chars 192..223.
        private static byte[] Courier10FontBitmap = new byte[] // 2048 bytes
        {
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x24,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,
            0x00,0x10,0x6c,0x24,0x38,0x40,0x00,0x20,0x08,0x40,0x10,0x00,0x00,0x00,0x00,0x08,
            0x00,0x10,0x6c,0x48,0x48,0xa0,0x1c,0x20,0x08,0x40,0x7c,0x10,0x00,0x00,0x00,0x10,
            0x00,0x10,0x48,0xfc,0x40,0x40,0x20,0x20,0x10,0x20,0x10,0x10,0x00,0x00,0x00,0x10,
            0x00,0x10,0x48,0x48,0x30,0x18,0x20,0x20,0x10,0x20,0x28,0x10,0x00,0x00,0x00,0x20,
            0x00,0x10,0x00,0x48,0x08,0xe0,0x30,0x00,0x10,0x20,0x28,0xfe,0x00,0xfc,0x00,0x20,
            0x00,0x00,0x00,0xfc,0x48,0x10,0x54,0x00,0x10,0x20,0x00,0x10,0x00,0x00,0x00,0x40,
            0x00,0x00,0x00,0x48,0x70,0x28,0x48,0x00,0x10,0x20,0x00,0x10,0x30,0x00,0x30,0x40,
            0x00,0x10,0x00,0x90,0x10,0x10,0x3c,0x00,0x10,0x20,0x00,0x10,0x20,0x00,0x30,0x80,
            0x00,0x00,0x00,0x90,0x10,0x00,0x00,0x00,0x08,0x40,0x00,0x00,0x60,0x00,0x00,0x80,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x00,0x00,0x40,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x78,0x10,0x70,0x70,0x18,0x7c,0x1c,0xfc,0x78,0x78,0x00,0x00,0x00,0x00,0x00,0x38,
            0x84,0x70,0x88,0x88,0x28,0x40,0x20,0x84,0x84,0x84,0x00,0x00,0x04,0x00,0x80,0x44,
            0x84,0x10,0x08,0x08,0x48,0x40,0x40,0x04,0x84,0x84,0x30,0x30,0x18,0xfc,0x60,0x04,
            0x84,0x10,0x10,0x30,0x48,0x78,0x78,0x08,0x78,0x84,0x30,0x30,0x20,0x00,0x10,0x04,
            0x84,0x10,0x20,0x08,0xfc,0x04,0x44,0x08,0x84,0x7c,0x00,0x00,0xc0,0xfc,0x0c,0x08,
            0x84,0x10,0x40,0x08,0x08,0x04,0x44,0x10,0x84,0x04,0x00,0x00,0x20,0x00,0x10,0x10,
            0x84,0x10,0x88,0x88,0x08,0x84,0x44,0x10,0x84,0x08,0x30,0x30,0x18,0x00,0x60,0x00,
            0x78,0x7c,0xf8,0x70,0x1c,0x78,0x38,0x10,0x78,0xf0,0x30,0x60,0x04,0x00,0x80,0x30,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x88,0x30,0xf8,0x3c,0xf0,0xfc,0xfc,0x3c,0xee,0x7c,0x3c,0xee,0xe0,0xee,0xce,0x38,
            0x88,0x10,0x44,0x44,0x48,0x44,0x44,0x44,0x44,0x10,0x08,0x44,0x40,0x6c,0xc4,0x44,
            0x98,0x28,0x44,0x80,0x44,0x50,0x50,0x80,0x44,0x10,0x08,0x48,0x40,0x6c,0xa4,0x82,
            0xa8,0x28,0x78,0x80,0x44,0x70,0x70,0x80,0x7c,0x10,0x08,0x50,0x40,0x54,0xa4,0x82,
            0xa8,0x28,0x44,0x80,0x44,0x50,0x50,0x8e,0x44,0x10,0x88,0x70,0x40,0x54,0x94,0x82,
            0x98,0x38,0x44,0x80,0x44,0x40,0x40,0x84,0x44,0x10,0x88,0x48,0x44,0x44,0x94,0x82,
            0x80,0x44,0x44,0x44,0x48,0x44,0x40,0x44,0x44,0x10,0x88,0x44,0x44,0x44,0x8c,0x44,
            0x88,0xee,0xf8,0x38,0xf0,0xfc,0xe0,0x38,0xee,0x7c,0x70,0xe6,0xfc,0xee,0xcc,0x38,
            0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x20,0x00,
            0xf8,0x38,0xf8,0x74,0xfe,0xee,0xce,0xee,0xee,0xee,0x7c,0x38,0x80,0xe0,0x20,0x00,
            0x44,0x44,0x44,0x8c,0x92,0x44,0x84,0x44,0x44,0x44,0x44,0x20,0x40,0x20,0x50,0x00,
            0x44,0x82,0x44,0x80,0x10,0x44,0x84,0x44,0x28,0x28,0x08,0x20,0x40,0x20,0x88,0x00,
            0x44,0x82,0x44,0x78,0x10,0x44,0x48,0x54,0x10,0x28,0x10,0x20,0x20,0x20,0x00,0x00,
            0x78,0x82,0x78,0x04,0x10,0x44,0x48,0x54,0x10,0x10,0x10,0x20,0x20,0x20,0x00,0x00,
            0x40,0x82,0x48,0x04,0x10,0x44,0x48,0x54,0x28,0x10,0x20,0x20,0x20,0x20,0x00,0x00,
            0x40,0x44,0x44,0xc4,0x10,0x44,0x30,0x54,0x44,0x10,0x44,0x20,0x10,0x20,0x00,0x00,
            0xe0,0x38,0xe2,0xb8,0x38,0x38,0x30,0x28,0xee,0x38,0x7c,0x20,0x10,0x20,0x00,0x00,
            0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x10,0x20,0x00,0xfe,//"_" new bottom
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0xe0,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// "_"old bottom
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x20,0x00,0x80,0x00,0x0c,0x00,0x1c,0x00,0xc0,0x10,0x10,0xc0,0x30,0x00,0x00,0x00,
            0x10,0x00,0x80,0x00,0x04,0x00,0x20,0x00,0x40,0x00,0x00,0x40,0x10,0x00,0x00,0x00,
            0x00,0x78,0xb8,0x74,0x74,0x78,0xfc,0x76,0x58,0x70,0x78,0x5e,0x10,0xa4,0xd8,0x78,
            0x00,0x84,0xc4,0x8c,0x8c,0x84,0x20,0x8c,0x64,0x10,0x08,0x48,0x10,0xda,0x64,0x84,
            0x00,0x7c,0x84,0x80,0x84,0xfc,0x20,0x84,0x44,0x10,0x08,0x70,0x10,0x92,0x44,0x84,
            0x00,0x84,0x84,0x80,0x84,0x80,0x20,0x84,0x44,0x10,0x08,0x50,0x10,0x92,0x44,0x84,
            0x00,0x8c,0xc4,0x84,0x8c,0x80,0x20,0x8c,0x44,0x10,0x08,0x48,0x10,0x92,0x44,0x84,
            0x00,0x76,0xb8,0x78,0x76,0x7c,0xfc,0x74,0xee,0x7c,0x08,0xce,0x7c,0xda,0xee,0x78,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0xf0,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x40,0x00,0xfc,
            0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x00,0x04,
            0xd8,0x76,0xdc,0x7c,0xf8,0xcc,0xce,0xee,0xcc,0xee,0x7c,0x20,0x20,0x20,0x00,0x04,
            0x64,0x8c,0x60,0x84,0x40,0x44,0x84,0x44,0x48,0x44,0x48,0x20,0x20,0x20,0x64,0x04,
            0x44,0x84,0x40,0x78,0x40,0x44,0x48,0x54,0x30,0x44,0x10,0x40,0x20,0x10,0x98,0x04,
            0x44,0x84,0x40,0x04,0x40,0x44,0x48,0x54,0x30,0x28,0x20,0x20,0x20,0x20,0x00,0x04,
            0x44,0x8c,0x40,0x84,0x44,0x4c,0x30,0x54,0x48,0x28,0x44,0x20,0x20,0x20,0x00,0x04,
            0x78,0x74,0xf8,0xf8,0x38,0x36,0x30,0x28,0xcc,0x10,0x7c,0x20,0x20,0x20,0x00,0xfc,
            0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x20,0x40,0x00,0x00,
            0xe0,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x20,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x30,0x00,0xee,0x20,0x7c,0x48,0x78,0x70,0x00,0x00,0x00,0x78,0x00,
            0x00,0x00,0x10,0x48,0x84,0x44,0x20,0x44,0x00,0x84,0x10,0x00,0x00,0x00,0x84,0x00,
            0x00,0x10,0x38,0x40,0x78,0x28,0x20,0xe0,0x00,0x3a,0x70,0x00,0x00,0x00,0x7a,0x00,
            0x00,0x00,0x44,0x40,0x48,0x7c,0x20,0x90,0x00,0x42,0x78,0x24,0x00,0x00,0x2a,0x00,
            0x00,0x00,0x40,0xf0,0x48,0x10,0x00,0xcc,0x00,0x42,0x00,0x48,0xfc,0xfc,0x32,0x00,
            0x00,0x10,0x44,0x20,0x78,0x7c,0x00,0x24,0x00,0x3a,0x00,0x90,0x04,0x00,0x7a,0x00,
            0x00,0x10,0x38,0x44,0x84,0x10,0x20,0x1c,0x00,0x84,0x00,0x48,0x04,0x00,0x84,0x00,
            0x00,0x10,0x10,0xfc,0x00,0x38,0x20,0x88,0x00,0x78,0x00,0x24,0x04,0x00,0x78,0x00,
            0x00,0x10,0x00,0x00,0x00,0x00,0x20,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x10,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x48,0x10,0x30,0x78,0x10,0x00,0x7e,0x00,0x00,0x30,0x30,0x00,0x80,0x80,0xc0,0x00,
            0x48,0x10,0x50,0x18,0x20,0x00,0x94,0x00,0x00,0x10,0x48,0x00,0x80,0x84,0xc2,0x00,
            0x30,0x10,0x20,0x08,0x00,0x98,0x94,0x00,0x00,0x10,0x48,0x00,0x82,0x88,0x44,0x30,
            0x00,0xfe,0x78,0x78,0x00,0x88,0x94,0x30,0x00,0x38,0x30,0x90,0x8c,0xf0,0xc8,0x00,
            0x00,0x10,0x00,0x00,0x00,0x88,0x74,0x30,0x00,0x00,0x00,0x48,0xfc,0x4e,0x3c,0x20,
            0x00,0x10,0x00,0x00,0x00,0x88,0x14,0x00,0x00,0x00,0x00,0x24,0x54,0x82,0x54,0x40,
            0x00,0x10,0x00,0x00,0x00,0x98,0x14,0x00,0x00,0x00,0x00,0x48,0x1e,0x04,0x9e,0x80,
            0x00,0xfe,0x00,0x00,0x00,0xec,0x14,0x00,0x10,0x00,0x00,0x90,0x0e,0x0e,0x0e,0x80,
            0x00,0x00,0x00,0x00,0x00,0x80,0x76,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x88,
            0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x70,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
        };








        private static int mFontTextureName = 0;




        private static void MakeFontTexture ( GR gr )
        {


            byte[] rgbaBuffer = new byte[128 * 128 * 4];


            // fill in buffer with RGBA version of font pixels
            byte val = (byte)0;
            int k = 0;
            for (int j = 0; j < 128; j++)
            {
                for (int i = 0; i < 128; i++)
                {
                    k = 4 * ((128 * (127 - j)) + i);
                    val = Courier10FontBitmap[(16 * j) + (i >> 3)];
                    val <<= (i & 0x7); // 0..7
                    if (0 != (val & 0x80))
                    {
                        // opaque white
                        rgbaBuffer[k + 0] = 255; // R
                        rgbaBuffer[k + 1] = 255; // G
                        rgbaBuffer[k + 2] = 255; // B
                        rgbaBuffer[k + 3] = 255; // A
                    }
                    else
                    {
                        // transparent
                        rgbaBuffer[k + 0] = 0; // R
                        rgbaBuffer[k + 1] = 0; // G
                        rgbaBuffer[k + 2] = 0; // B
                        rgbaBuffer[k + 3] = 0; // A
                    }
                }
            }


            // create an OpenGL texture and transfer data to the texture
            int[] temp = new int[1];
            gr.glGenTextures( 1, temp );
            mFontTextureName = temp[0];
            gr.glBindTexture( GR.GL_TEXTURE_2D, mFontTextureName );

            gr.glTexParameteri( GR.GL_TEXTURE_2D, GR.GL_TEXTURE_MAG_FILTER, GR.GL_NEAREST );
            gr.glTexParameteri( GR.GL_TEXTURE_2D, GR.GL_TEXTURE_MIN_FILTER, GR.GL_NEAREST );
            gr.glTexImage2D( GR.GL_TEXTURE_2D, 0, GR.GL_RGBA, 128, 128, 0, GR.GL_RGBA, GR.GL_UNSIGNED_BYTE, rgbaBuffer );
        }









        public static void FontPrint ( GR gr, float x, float y, String asciiText )
        {
            int n = 0;
            n = asciiText.Length;
            if (n <= 0)
            {
                return;
            }


            if (0 == mFontTextureName)
            {
                MakeFontTexture( gr );
            }

            // DISABLE Z-WRITES AND Z-TESTING
            gr.glDisable( GR.GL_DEPTH_TEST );

            gr.glEnable( GR.GL_BLEND );
            gr.glBlendFunc( GR.GL_SRC_ALPHA, GR.GL_ONE_MINUS_SRC_ALPHA );
            gr.glEnable( GR.GL_TEXTURE_2D );
            gr.glBindTexture( GR.GL_TEXTURE_2D, mFontTextureName );


            gr.glBegin( GR.GL_TRIANGLES );


            float du = 0.0f;
            float dv = 0.0f;
            du = (0.0625f);
            dv = (0.1250f);

            int i = 0;
            int j = 0;
            int k = 0;
            int index = 0;
            float u = 0.0f;
            float v = 0.0f;
            for (k = 0; k < n; k++)
            {
                index = (int)(asciiText[k]);

                if (index > 255)
                {
                    index = 0;
                }
                else if (index >= 192)
                {
                    index -= 96;
                }
                else if (index >= 32)
                {
                    index -= 32;
                }
                else if (index < 32)
                {
                    index = 0;
                }

                if (index < 0) index = 0;
                if (index >= 128) index = 0;

                i = (index & 0xf);
                j = (7 - (index >> 4));

                u = du * ((float)i);
                v = dv * ((float)j);

                gr.glTexCoord2f( u, v );
                gr.glVertex3f( x + (float)(FONT_WIDTH * k), y - (float)(FONT_HEIGHT), 0.0f );
                gr.glTexCoord2f( (u + du), v );
                gr.glVertex3f( x + (float)(FONT_WIDTH * (k + 1)), y - (float)(FONT_HEIGHT), 0.0f );
                gr.glTexCoord2f( u, (v + dv) );
                gr.glVertex3f( x + (float)(FONT_WIDTH * k), y, 0.0f );

                gr.glTexCoord2f( u, (v + dv) );
                gr.glVertex3f( x + (float)(FONT_WIDTH * k), y, 0.0f );
                gr.glTexCoord2f( (u + du), v );
                gr.glVertex3f( x + (float)(FONT_WIDTH * (k + 1)), y - (float)(FONT_HEIGHT), 0.0f );
                gr.glTexCoord2f( (u + du), (v + dv) );
                gr.glVertex3f( x + (float)(FONT_WIDTH * (k + 1)), y, 0.0f );
            }

            gr.glEnd( );

            gr.glDisable( GR.GL_TEXTURE_2D );
            gr.glDisable( GR.GL_BLEND );
            gr.glEnable( GR.GL_DEPTH_TEST );

        }



    }
}
